< previous page page_539 next page >

Page 539
When you click the OK button, Visual Basic redisplays the input prompt and waits for your reply. If you enter another invalid value, you see the error message, and then you see the prompt again. This is the Resume exit method in action. You can't get beyond this screen until you enter a valid value.
This can be very frustrating for users. What if they don't know what value to enter here? Are they stuck in this terrible error handler forever? Whenever you use the Resume keyword, you should give your users an option to ignore the error and move on or cancel the action completely. Those options are covered next.
Using Resume Next to Exit the Error Handler
Using the Resume Next method to exit an error handler allows your user to get past a problem spot in the program as if no error has occurred. This is useful when you use code within the error handler to fix the problem, or when you think the program can go on even though an error has been reported.
Deciding whether to continue the program even though an error has been reported is sometimes a tough call. It is usually not a good idea to assume that your program will work fine even though an error is reported. This is especially true if the error that occurs is one related to physical devices (missing diskette, lost communications connection, and so on) or file errors (missing, corrupted, or locked data files, and so on). The Resume Next keywords are usually used in error-handling routines that fix any reported error before continuing.
To illustrate the use of Resume Next, add a new command button to the project. Set its Name property to cmdResumeNext and its Caption property to Next. Now enter the code in Listing 14.6 behind the button's Click event.
Type.gifListing 14.6. Using the Resume Next keywords.
Private Sub cmdResumeNextErr_Click()
    '
    ' show use of resume next
    '
    On Error GoTo LocalErr
    '
    Dim intValue As Integer
    Dim strMsg As String
    Dim lngReturn As Long
    '
    intValue = InputBox("Enter a valid Integer")
    MsgBox "intValue has been set to " + CStr(intValue)
    GoTo LocalExit
    '
continues

 
< previous page page_539 next page >

If you like this book, buy it!